package org.example.util.log;

/**
 * @auther admin闫
 * @Descriptopn
 * @date 2024/4/4 23:29
 */
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Logac {

    private static final String LOG_FILE = "./log.txt"; // 日志文件路径

    public static void log(String message) {
        try (FileWriter fileWriter = new FileWriter(LOG_FILE, true);
             PrintWriter printWriter = new PrintWriter(fileWriter)) {
            // 获取当前时间
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String timestamp = dateFormat.format(new Date());

            // 输出日志消息到文件
            printWriter.println("[" + timestamp + "] " + message);
            System.out.println("[" + timestamp + "] " + message);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

